class Game
  attr_reader :name,:levels,:levelno
  def initialize(name="Untitled",levels=0)
    @name=name
    @levels=levels
    @levelno=0
  end
  def getLevelNo
    return @levelno
  end
  def to_s
    return "{[COMPONENT::Game]::Name="+@name+"}\n"
  end
end

class Storyline
  attr_reader :eventType,:arg,:script 
  #eventType=trigger, arg=trigger argument, script=script to be executed
  attr_reader :AfterLevel,:OnReach
  #triggers
  @AfterLevel=0 
  #after a level ends and before he next begins. arg=a string: levelno
  @OnReach=1 
  #when the character reaches a position. args=a string: "x;y"
 public
  def initialize(eventType=@AfterLevel,arg="",script="null.rb")
    @eventType=eventType
    @arg=arg
    @script=script
  end
  def to_s
    return "{[COMPONENT::Storyline]::Script="+@script+"}\n"
  end
end

=begin
class Item
  attr_reader :name, :id, :img, :onUseProc
  @@iTEMindex=0
  #name=display name, intName=internal name - automatically generated, sprite=image
  def initialize(name="untitled", img="null.png", onUseProc = Proc.new)
    @name=name
    @img=img
    @onUseProc = onUseProc
    @id=@@iTEMindex
    @@iTEMindex+=1
  end
end  
=end

class Building
  def initlialize(x,y)
    
  end
  def draw
    
  end
end

class Weapon
  attr_reader :name,:type,:atk,:mp,:anim,:special,:id
  #name=display name, type=melee or missile or arrow, atk=damage dealt by weapon, mp=magic points cost,
  #anim=script defining attack animations, special=special abilities script, intName=automatically generated internal name
  Melee=0
  Missile=1
  Magic=2
  @@wEPindex=0
  def initialize(name="unnamed",type=Melee,atk=1,mp=1,anim="null.rb",special="null.rb")
    @name=name
    @type=type
    @atk=atk
    @mp=mp
    @anim=anim
    @special=special
    @id=@@wEPindex
    @@wEPindex+=1
  end
  def to_s
    return "{[COMPONENT::Weapon]::Name="+@name+"}\n"
  end
end

=begin
class Level
  attr_reader :name,:number,:dir,:objectMap,:terrainMap,:buildingMap
  #name=display name, number=order of level, map=terrain/map script
  def initialize(name="untitled",number=0,map="/data/maps")
    @name=name
    @number=number
    @dir=dir
    @objectMap=@dir+"/objects.map"
    @terrainMap=@dir+"/terrain.map"
    @buildingMap=@dir+"/buildings.map"
  end
  def to_s
    return "{[COMPONENT::Level]::Name="+@name+"}\n"    
  end
end
=end

class Material #TODO: add maptile handle #loaded by maprender
  @@materials = {}
  Root="data/maps/materials.def"
  ScriptRoot="data/materials/scripts"
  SpriteRoot="img/sprites/map"
  Terrain=0
  Item=1
  Building=2
  Door=3
  attr_reader :name,:sprite,:traversable,:scriptEnabled,:script,:imgObj
  #name=id in map files, sprite=image, traversable=can characters cross this terrain?
  def initialize(window,name="unnamed",sprite="null.png",traversable=true,scriptEnabled=false,script="",type=Terrain)
    @name=name
    parseanim(sprite)
    @traversable=traversable
    @scriptEnabled=scriptEnabled
    @type=type
    if @name=="unnamed"
      $flog.warn("Material::Init") {"Name left to default for material no. #{@@materials.size}"}
    end
    #@imageObj=
    @@materials[@name]=self
  end
  def parseanim(sprite)

  end
  def to_s
    return "{[COMPONENT::Material]::Name="+@name+"}\n"    
  end
end

nullAnim = {}
nullAnim["Walk-Forward"] = "null.png"
class Character
  DefRoot="data/characters/chars.def"
  ScriptRoot="data/characters/scripts"
  MapObjectRoot="data/maps/%current_map%char.obj"
  attr_reader :name,:animations
  #name=identification name, animations=hash of images associated with action keys
  def initialize(name="unnamed",animations=nullAnim)
    @name=name
    @animations=animations
  end  
  def to_s
    return "{[COMPONENT::Character]::Name="+@name+"}\n"    
  end
end

=begin
class MenuIcon
  Root="data/maps/%current_level%.map"
  attr_reader :x, :y, :tile, :reference
  #x=x coordinate, y=y coordinate
  #type=character, terrain, item, or building(piece)
  #reference=name of material object in memory which contains the object details
  def initialize(image="null.png",reference=Item.new,name="untitled")
    @image=image
    @type=type
    @reference=reference
    @name=name
  end  
  def register
    
  end
  def to_s
    return "{[COMPONENT::MenuIcon]::Image="+@imageid+"}\n"   
  end  
end
=end

=begin
objNull=Array.new
objNull[0]=MapObject.new
class Map
  Root="data/maps/%current_level%.map"
  attr_reader :name, :width, :height
  #name=display name, width=x value, height=y value
  attr_reader :objects
  #array of mapObject objects
  def initialize(name="untitled",bgimage="null.png",bumpmap="null.png",width=1,height=1,objects=objNull)
    @name=name
    @bgimage=bgimage
    @bumpmap=Gosu::Image.new($window,bumpmap)
    @width=width
    @height=height
    @objects=objects
  end  
  def traversable?(x,y)
    
  end
  def to_s
   return "{[COMPONENT::Map]::Name="+@name+"}\n"   
  end  
end
=end

class Map
  Root="data/maps/%current_level%.map"
  attr_reader :name,:worldId,:collisionMap,:bg,:collisionPager,:nodeMap
  #name=display name, number=order of level, map=terrain/map script
  def initialize(name="untitled", world_id=0, bg="null.png",bump="null.bmp",bumppage="null.rb",nodex=10,nodey=10)
    @name=name
    @worldId=world_id
    @bg=Gosu::Image.new($window, bg, false)
    @collisionMap=CollisionMap.new(bump)
    @collisionPager=bumppage
    @nodeMap=NodeMap.new(@collisionMap,nodex,nodey)
  end
  def width
    return @collisionMap.width
  end
  def height
    return @collisionMap.height
  end
  def traversable?(x,y)
    return @collisionMap.traversable?(x,y)
  end
  def to_s
    return "{[COMPONENT::Level]::Name="+@name+"}\n"    
  end
end

#################################
#################################


#################################
#Code below not finished
#################################

#Data hash structures
#TODO: Document the hash structures

#Sub hashes
#None as of yet

#Hash examples
#game = {"Name" => "", "Levels" => ""}
#
#
#
#